{% extends 'index.html' %}
{% load comment_tags %}
{% block page-container %}
    <div class="jumbotron row">
        <div class="article-detail">
            <h3>{{ article_obj.title }}</h3>
            <h6>{{ article_obj.author }}</h6>
            <div>{{ article_obj.content|safe }}</div>
        </div>
    </div>
{% endblock %}

 <!-- 评论树-->
{% block comment_trees %}
    <div class="jumbotron row">
        {% build_comment_tree article_obj.comment_set.select_related %}
    </div>

    <div class="jumbotron row">
        <form action="{% url 'article_detail' article_id %}" method="POST" novalidate>
        {% csrf_token %}
            <div class="comment-area">
                <div class="replay-comment-user"></div>
                <div class="reply-area" style="position: relative;">

                    {% if not request.user.is_authenticated %}
                    <div style="text-align:center;line-height:200px;position: absolute;top:0;left:0;right:0;bottom: 0;background-color: rgba(255,255,255,.6)">
                        您需要登录后才可以回帖 <a href="{% url 'login' %}">登录</a> | <a href="{% url 'register' %}">立即注册</a>
                    </div>
                    {% endif %}
                    <textarea name="content" style="width: 100%;height:200px;visibility:hidden;" id="texts"></textarea>

                </div>
                <div>
                    <span class="hide" id="sreply"></span>
                    <input type="text" class="hide" id="reply" name="reply">
                    <div class="reply-btn">
{#                        <span><span>21</span>/255字</span>#}
                        <input type="submit" class="btn btn-primary" value="发表回复">
{#                        <a class="btn btn-primary" id="call">发表回复</a>#}
                    </div>
                </div>
            </div>
        </form>
    </div>
{% endblock %}



  <!-- 下方JS -->
{% block foot_js %}
    <script charset="utf-8" src="/static/plugins/kindeditor/kindeditor-min.js"></script>
    <script charset="utf-8" src="/static/plugins/kindeditor/lang/zh_CN.js"></script>
    <script>
        var editor;
        //插件
        KindEditor.ready(function (K) {
            editor = K.create('textarea[name="content"]', {
                resizeType: 1,
                allowPreviewEmoticons: false,
                allowImageUpload: false,
                items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                    'insertunorderedlist', '|', 'emoticons', 'image', 'link']
            });
        });
    $(function() {
        //
        $.ajaxSetup({//当前所有ajax发送 全局
            beforeSend: function (xhr, settings) {//发送ajax前 先执行这个函数
                xhr.setRequestHeader('X-CSRFtoken', $.cookie('csrftoken'));
            }
        });
    });

    $('.calls').click(function(){
        //var s=$(this).parent().children('span').text();//要@的回复标签
        var s=$(this).parent().children('.pid').text();//要@的回复标签
        //                  父级 的上的兄弟的下级们
        //var nickname=$(this).parent().prev().children('.nick').text();
        var nickname=$(this).text();
        //alert(nickname);
        var n = $('#reply').val(s);//回复的id
        var sp=$('#sreply').removeClass('hide');//显示回复的昵称
        sp.text('@'+nickname);
        n.val(s);
        var m=$('textarea[name="content"]').value(s);
        alert(m);
    });

    $('#up').click(function(){
        var up=$(this).children('div');
        var up_count=up.text();
        URL=window.location.pathname;
        //alert(URL);
        $.ajax({
            url: URL,
            type: 'POST',
            data: {'up_count':up_count,'URL':URL},//
            dataType: 'JSON',
            headers:{'X-CSRFtoken':$.cookie('csrftoken')},
            success: function (arg) {
                if(arg.edi){
                    up.text(arg.up_count);//更新内容

                }else {

                }
            }

        })
    });

    $('#down').click(function(){
        var down=$(this).children('div');
        var down_count=down.text();
        //alert(down_count);
        URL=window.location.pathname;
        //alert(URL);
        $.ajax({
            url: URL,
            type: 'POST',
            data: {'down_count':down_count,'URL':URL},//
            dataType: 'JSON',
            headers:{'X-CSRFtoken':$.cookie('csrftoken')},
            success: function (arg) {
                if(arg.edi){
                    alert(arg.down_count);
                    down.text(arg.down_count);//更新

                }else {
                //window.location.reload();//刷新页面
                }
            }

        })
    })
    </script>
{% endblock %}